package com.xxx.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxx.common.Result;
import com.xxx.entity.BrainGain;
import com.xxx.entity.query.BrainGainQuery;
import com.xxx.service.IBrainGainService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xxx
 * @since 2024-11-24
 */
@RestController
@RequestMapping("/braingain")
@Tag(name = "人才回流管理")
public class BrainGainController {
    @Autowired
    private IBrainGainService brainGainService;

    @PostMapping("/add")
    @Operation(summary = "添加人才回流")
    public Result add(@RequestBody BrainGain brainGain){
        Boolean flag = brainGainService.save(brainGain);
        return flag ? Result.success("添加人才回流成功") : Result.error("添加人才回流失败");
    }

    @GetMapping("/delete/{brainGainId}")
    @Operation(summary = "删除人才回流")
    public Result delete(@PathVariable Integer brainGainId){
        Boolean flag = brainGainService.removeById(brainGainId);
        return flag ? Result.success("删除人才回流成功") : Result.error("不存在该人才回流Id");
    }

    @PutMapping("/update")
    @Operation(summary = "修改人才回流")
    public Result update(@RequestBody BrainGain brainGain){
        Boolean flag = brainGainService.updateById(brainGain);
        return flag ? Result.success("修改人才回流成功") : Result.error("修改人才回流失败");
    }

    @GetMapping("/selectByPage/{current}/{size}")
    @Operation(summary = "分页查询人才回流")
    public Result selectByPage(@PathVariable Integer current, @PathVariable Integer size){
        IPage<BrainGain> page = brainGainService.page(new Page<>(current,size));
        return Result.success(page);
    }

    @PostMapping("/selectByCondition")
    @Operation(summary = "根据标题、类型、Id条件查询人才回流")
    public Result selectByCondition(@RequestBody BrainGainQuery brainGainQuery){
        LambdaQueryWrapper<BrainGain> lqw = new LambdaQueryWrapper<>();
        lqw.like(brainGainQuery.getBrainGainTitle()!=null&&!brainGainQuery.getBrainGainTitle().equals(""),
                        BrainGain::getBrainGainTitle,brainGainQuery.getBrainGainTitle())
                .eq(brainGainQuery.getBrainGainCategory()!=null&&!brainGainQuery.getBrainGainCategory().equals(""),
                        BrainGain::getBrainGainCategory,brainGainQuery.getBrainGainCategory())
                .eq(brainGainQuery.getBrainGainId()!=null,BrainGain::getBrainGainId,brainGainQuery.getBrainGainId());
        IPage<BrainGain> page = brainGainService.page(new Page<>(brainGainQuery.getCurrent(), brainGainQuery.getSize()),
                lqw);
        return Result.success(page);
    }
}

